package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Goal;
import entity.Task;
import entity.User;

import service.TaskService;
import service.UserService;
import util.web.ServletUtil;

public class EditTaskSubmit extends HttpServlet {

	private static final long serialVersionUID = 1L;

	
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		UserService userService = new UserService();
		User user = userService.findUserByUsername(username);
		
		Task task = (Task) request.getSession().getAttribute("task");
		Goal goal = (Goal) request.getSession().getAttribute("goal");
		
		String taskname = request.getParameter("taskname");
		String starttime = request.getParameter("starttime");
		String endtime = request.getParameter("endtime");
		String descript = request.getParameter("descript");
		String state = request.getParameter("state");
		String level = request.getParameter("level");
		String bar = request.getParameter("bar");
		
		
		
		TaskService taskService = new TaskService();
		taskService.updateTaskByid(taskname, starttime, endtime, descript, state, level, bar, user.getId(), goal.getId(), task.getId());
		System.out.println("aaaaaaaaaaaaaaa");
		ServletUtil.sendRedirect(response, "gotask.jspx");
		
		
		
		
		
		
	}

}
